package com.itheima.myscoket;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class Demo2 {
    public static void main(String[] args) throws IOException {
        //接收找码头
        DatagramSocket ds = new DatagramSocket(10002);
        //创建箱子接收
        while (true) {
            byte[] bytes = new byte[1024];
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
            //接收
            ds.receive(dp);
            //获取箱子的礼物,实际长度
            int length = dp.getLength();
            System.out.println(new String(bytes, 0, length));
        }
    }
}
